package com.example.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.example.constant.MqConstant.*;

/**
 * rabbitMq配置类
 *
 * @author Lv
 * @date 2023/4/1
 */
@Configuration
public class RabbitMqConfig {
    /**
     * 定义队列 命名：testDirectQueue
     *
     * @return
     */
    @Bean
    public Queue queue() {
        return new Queue(QUEUE_NAME, true);
    }

    /**
     * 定义交换机 命名：testDirectExchange
     *
     * @return
     */
    @Bean
    DirectExchange directExchange() {
        return new DirectExchange(EXCHANGE_NAME, true, false);
    }

    /**
     * 绑定队列到交换机 并设置用于匹配键：testRouting
     *
     * @return
     */
    @Bean
    Binding bindingDirect() {
        return BindingBuilder.bind(queue()).to(directExchange()).with(ROUTING_KEY_NAME);
    }
}
